import logging

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from cookbook2.lib.base import BaseController, render
from cookbook2 import model

log = logging.getLogger(__name__)

class RegisterController(BaseController):
    c.errlogin = ''
    c.errpass = ''

    def index(self):
        # Return a rendered template
        #return render('/login.mako')
        # or, return a string
        #return 'Hello World'
		#q = model.Session.query(model.User)
		return render('/register.mako')


    def register(self):
        newuser = model.User()
        newuser.login = request.params['login']
        newuser.password = request.params['pass']
        
        # Attach the object to the session.
        model.Session.add(newuser)

        # Commit the transaction.
        model.Session.commit()
        #return render('/register.mako')
        redirect(url(controller="login", action="login"))